<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">

		<script src="plugins/layui/layui.js"></script>
		<style type="text/css">
			.layui-table-view .layui-table td,
			.layui-table-view .layui-table th {
				padding: 0
			}
		</style>
	</head>

	<body>
		<div class="breadcrumbnav">
			<span class="layui-breadcrumb " lay-separator="·">
          <a ><cite>首页</cite></a>
          <a ><cite>商品管理</cite></a>
          <a ><cite>下架商品</cite></a>
        </span>
		</div>
		<div class="kit-doc">
			<!-- 标题 -->
			<div class="kit-doc-title">

				<fieldset>
					<legend>
						<a name="blockquote">下架</a>
					</legend>
				</fieldset>
			</div>
			<!-- 标题 end-->
			<!-- 概述 -->
			<div class="boderbox">
				<!--<div class="rowtop">-->
				<!--<button class="layui-btn addbtn">
                   添加+
                </button>-->
				<!--<form class="layui-form searchform" action="" id="comSearchForm">
                    <select name="city" lay-verify="">
                      <option value="oderid">条码</option>
                      <option value="name">名称</option>
                    </select> 
                    <div class="layui-input-inline">
                      <input type="text" name="text" required lay-verify="required" placeholder="输入关键字" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-btn-group">
                      <button class="layui-btn">搜索</button>
                      <button class="layui-btn layui-btn-normal">重置</button>
                    </div>
                </form> -->
				<!--</div>-->

				<div class="layui-tab-content notab">
					<div class="layui-tab-item layui-show">
						<table class="layui-table " lay-filter="table100" id="cMtable"></table>

						<!--<table class="layui-table "  lay-size="lg" lay-data="{page:'false', id:'commodityclass',height: 'full-10'}" lay-filter="test" id="commodityclass">
                        <thead>
                            <tr>
                               
                                <th lay-data="{field:'id', width:50}"> 
                                    <input type="checkbox" name="select"  lay-skin="primary" >
                                </th>
                               
                                <th lay-data="{field:'a33', width:300,sort: true}">操作</th>
                                <th lay-data="{field:'a1', width:70}">序号</th>
                                <th lay-data="{field:'a2', width:200}">条码</th>
                                <th lay-data="{field:'Consignee', width:120}">产品品牌</th>
                                <th lay-data="{field:'phone', width:200}">产品名称</th>
                                <th lay-data="{field:'operation', width:100}">产品型号</th>
                                <th lay-data="{field:'a3', width:150}">产品小图</th>
                                <th lay-data="{field:'a4', width:120}">产品重量</th>
                                <th lay-data="{field:'a5', width:120}">产品单位</th>
                                <th lay-data="{field:'a6', width:120}">产品规格</th>
                                <th lay-data="{field:'a7', width:120}">销售状态</th>
                                <th lay-data="{field:'a8', width:120}">销售类别</th>
                            </tr> 
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                   <input type="checkbox" name="select"  lay-skin="primary" >
                                </td>
                                <td>
                                    <button class="layui-btn layui-btn-mini" lay-event="editp">编辑产品</button>
                                    <button class="layui-btn layui-btn-normal" lay-event="editm">编辑销售</button>
                                    <button class="layui-btn layui-btn-danger" lay-event="downm">下线停售</button>
                                </td>
                                <td>1</td>
                                <td>6948505400038</td>
                                <td>那胜</td>
                                <td>那胜牌欧美酸枝</td>
                                <td>MH-12</td>
                                <td></td>
                                <td>18厘</td>
                                <td>厘</td>
                                <td>厘</td>
                                <td>已上架</td>
                                <td></td>

                            </tr>
                           
                        </tbody>
                    </table>-->

					</div>
				</div>
				<!--图片的iframe-->
				<iframe id="framFile" name="framFile" style="display: none;"></iframe>
				<iframe id="framFile1" name="framFile1" style="display: none;"></iframe>
				<script type="text/html" id="checkboxTpl">
					<input type="checkbox" name="recommendState" value="{{d.id}}" title="推荐" lay-filter="lockDemo" {{ d.recommendState==1 ? 'checked' : '' }} disabled>
				</script>

				<script type="text/html" id="checkboxTpl2">

					<input type="checkbox" name="shelfState" value="{{d.id}}" title="上架" lay-filter="lock2Demo" {{ d.shelfState==1 ? 'checked' : '' }}>
				</script>
				<script type="text/html" id="checkboxTpl3">

					<input type="checkbox" name="hotState" value="{{d.id}}" title="热销" lay-filter="lock3Demo" {{ d.hotState==1 ? 'checked' : '' }} disabled>
				</script>

				<!--上架商品的表格内容-->
				<script id="addBox" type="text/html">
					<div class=" layui-layer-wrap">
						<form class="layui-form layui-form-pane" action="" id="addform">
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">姓名</label>
									<div class="layui-input-block">
										<input type="text" name="salesmanName" autocomplete="off" lay-verify="number|required" placeholder="" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">业务员编号</label>
									<div class="layui-input-block">
										<input type="text" name="openId" autocomplete="off" lay-verify="required" placeholder="" class="layui-input">
									</div>
								</div>
							</div>

							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">加入时间</label>
									<div class="layui-input-block">
										<input type="text" id="addTime" name="addTime" class="layui-input">
										<!-- <input type="text" name="createTime" autocomplete="off" lay-verify="required"  placeholder="" class="layui-input">-->
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">地区编码</label>
									<div class="layui-input-block">
										<input type="text" name="adcode" autocomplete="off" lay-verify="number|required" placeholder="" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">地区</label>
									<div class="layui-input-block">
										<input type="text" name="region" autocomplete="off" lay-verify="required" placeholder="" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">微信id</label>
									<div class="layui-input-block">
										<input type="text" name="wechatId" lay-verify="required" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>

							<div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
								<div class="layui-form-item">
									<label class="layui-form-label">介绍</label>
									<div class="layui-input-block">
										<textarea name="introduce" placeholder="请输入客服介绍" class="layui-textarea"></textarea>

									</div>
								</div>
							</div>
						</form>
						<div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
							<div class="layui-form-item">

								<!--<form action="http://hsmytest.vrdete.com/api/qiniu/update" method="post"  enctype="multipart/form-data" target="framFile"  class="updataform"  >-->
								<!--<input type="file" name="files"  multiple="true" class="file_upload" />  </form>-->

								<form action="#" method="post" enctype="multipart/form-data" target="framFile1" class="updataform1 imgbox">

									<input type="button" class="layui-btn-primary imgbtn" value="选择头像" />
									<input type="file" class=" imgfile" name="files" multiple="true" value="选择文件" accept="image/*" onchange="xmTanUploadImg(this)" />
									<input type="button" class="layui-btn upNewimg" value="确认上传" style="" />

									<img id="xmTanImg" class="xmTanImg" />

								</form>

							</div>

						</div>

					</div>
				</script>
				<!--上架商品的表格内容end-->

				<script src="js/jquery-3.2.1.min.js"></script>
				<script type="text/javascript" src="js/allajax.js"></script>

				<script>
					layui.use(['layer', 'form', 'element', 'table'], function() {
						var layer = layui.layer,
							form = layui.form,
							element = layui.element,
							table = layui.table,
							laypage = layui.laypage;
						//  目录查询全部树
						var tableArray = new Array();
						cMListFn(1, 100);

						function cMListFn(curr, limit) {
							AjaxPostFn('system/commoditdetails/selectallpage?page=' + curr + '&pagesize=' + limit, "{'tosort':'asc','page':" + curr + ",'pagerow':" + limit + ", 'sorting':'present_price','shelfState':'0'}", function(jsonData) {
								if(jsonData.dataResultList) {

								} else {
									$.each(jsonData.pageInfo.list, function(i, obj) {
										tableArray.push({
											"id": obj.id,
											//								"operation": " <a class='layui-btn ' lay-event='updataFile' name='files'>上传主图</a>",
											"commodityNumber": obj.commodityNumber,
											"title": obj.title,
											"commodityWeigh": obj.bizCommoditiesList[0].commodityWeigh,
											"commodityUnit": obj.bizCommoditiesList[0].commodityUnit,
											"commodityModel": obj.bizCommoditiesList[0].commodityModel,
											"tablemainphoto": "<img src='" + IMGUrl + '' + obj.mainPhoto + "' alt='分类主图' class='classifyimg'>",
											"salesVolume": obj.salesVolume,
											"presentPrice": obj.presentPrice,
											"merchantNumber": obj.merchantNumber,
											"recommendState": obj.recommendState,
											"shelfState": obj.shelfState,
											"commodityId": obj.commodityId,
											"shortName": obj.shortName,
											"smallTitle": obj.smallTitle,
											"listingDate": obj.listingDate,
											"offlineDate": obj.offlineDate,
											"originalPrice": obj.originalPrice,
											"saleUnit": obj.saleUnit,
											"hotState": obj.hotState,
											"commodityStar": obj.commodityStar,
											"describes": obj.describes,
											"giftBarCodes": obj.giftBarCodes,
											"withGiftIcon": obj.withGiftIcon,
											"withGiftPhotos": obj.withGiftPhotos,
											"introduceUrl": obj.introduceUrl,
											"watchFrequency": obj.watchFrequency,
											"createDate": obj.createDate,
											"createId": obj.createId,
											"updateDate": obj.updateDate,
											"updateId": obj.updateId,
											"catalogId": obj.catalogId,
											"exhibitionPhoto": obj.exhibitionPhoto,
											"introduce": obj.introduce,
											"bizCommodityForSalePrice": obj.bizCommodityForSalePrice,
											"bizCommoditys": obj.bizCommoditys,
											"bizCommodityForSalePrices": obj.bizCommodityForSalePrices,
											"adcode": obj.adcode,
											"bizMerchantInfo": obj.bizMerchantInfo,
											"bizCommodityForSaleCategory": obj.bizCommodityForSaleCategory,
										});
									})
								}

								//展示已知数据
								table.render({
									elem: '#cMtable',
									cols: [
										[ //标题栏
											{
												type: 'numbers',
												fixed: 'left',
												title: '行号'
											}, {
												field: 'id',
												minWidth: '0%',
												width: '0%',
												type: 'space',
												style: 'display:none'
											},
											//									{field: 'operation',width: 250,title: '操作'},
											{
												field: 'commodityNumber',
												width: 150,
												title: '条码'
											}, {
												field: 'title',
												width: 250,
												title: '名称'
											}, {
												field: 'commodityWeigh',
												width: 100,
												title: '重量'
											}, {
												field: 'commodityUnit',
												width: 100,
												title: '单位'
											}, {
												field: 'commodityModel',
												width: 100,
												title: '规格'
											}, {
												field: 'tablemainphoto',
												width: 150,
												title: '主图'
											}, {
												field: 'presentPrice',
												width: 100,
												title: '产品价格'
											}, {
												field: 'merchantNumber',
												width: 100,
												title: '数量'
											}, {
												field: 'salesVolume',
												width: 100,
												title: '销量'
											},
											//									{field: 'recommendState',width: 100,title: '是否推荐',templet: '#checkboxTpl',unresize: true ,fixed: 'right'},
											//									{field: 'hotState',width: 100,title: '是否热销',templet: '#checkboxTpl3',unresize: true ,fixed: 'right'},
											{
												field: 'shelfState',
												width: 100,
												title: '是否上架',
												templet: '#checkboxTpl2',
												unresize: true,
												fixed: 'right'
											}

										]
									],
									data: tableArray,
									size: 'lg',
									even: true,
									page: true, //是否显示分页
									done: function() {
										//图片点击放大
										TopimgFn();

										//								laypage.render({
										//								    elem: 'layui-table-page1' //注意，这里的 test1 是 ID，不用加 # 号
										//								    ,count: jsonData.pageInfo.total//数据总数，从服务端得到
										//								    ,jump: function(obj, first){
										//									    //obj包含了当前分页的所有参数，比如：
										//									    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
										//									    console.log(obj.limit); //得到每页显示的条数
										//									    //首次不执行
										//									    if(!first){
										//									      //do something
										//									      cMListFn(obj.curr,obj.limit);
										//									    }
										//									}
										//								});

									}
								}); //数据渲染结束

							})

						} //cMListFn函数结束

						//				//是否推荐的开关
						//				form.on('checkbox(lockDemo)', function(obj) {
						//					var recommendState;
						//					obj.elem.checked ? recommendState= 1  : recommendState= 0 ;
						//					PdetUpdatebyidFn("{'id':'" + this.value + "','recommendState':'" + recommendState + "'}");
						//					
						//				});
						//				
						//是否上架的开关
						form.on('checkbox(lock2Demo)', function(obj) {
							var shelfState;
							obj.elem.checked ? shelfState = 1 : shelfState = 0;
							PdetUpdatebyidFn("{'id':'" + this.value + "','shelfState':'" + shelfState + "'}")
						});
						//				

						//				//监听单元格编辑
						//				table.on('edit(table100)', function(obj) {
						//					var value = obj.value //得到修改后的值
						//						,
						//						data = obj.data //得到所在行所有键值
						//						,
						//						field = obj.field; //得到字段
						//						PdetUpdatebyidFn("{'id':'" + data.id + "','title':'" + data.title + "'}")
						//					
						//				});

						//监听表格内的按钮
						table.on('tool(table100)', function(obj) {
							var data = obj.data;
							if(obj.event === 'updataFile') {
								//上传主图
								layer.open({

									title: '上传图片',
									area: ['390px', '260px'],
									shade: 0,
									maxmin: true,
									btn: ['上传'],
									content: ' <form action="'+AllUrl+'api/qiniu/update" method="post"  enctype="multipart/form-data" target="framFile"  class="updataform"  >  <input type="file" name="files"  multiple="true" class="file_upload" />  </form>',
									yes: function() {
										thisid = data.id;
										$(".updataform").submit();

									},
									success: function(layero) {}
								});
								var thisid = 1;
								var framFile = document.getElementById('framFile');
								var imgdata;
								framFile.onload = function() {
									imgdata = framFile.contentWindow.document.getElementsByTagName("pre")[0].innerHTML;
									imgdata = JSON.parse(imgdata).dataResultObj[0];
									console.log(imgdata)

									AjaxPostFn('system/commoditdetails/updatebyid', "{'id':'" + thisid + "','mainPhoto':'" + imgdata + "'}", function(jsonData) {
										console.log(jsonData)
										if(jsonData.htmlState.status == 200) {
											layer.msg("修改成功");
											layer.closeAll();
											location.reload();
										}

									});

								}

							} else if(obj.event === 'ModThis') {

							}
						})
					});

					function PdetUpdatebyidFn(data) {
						AjaxPostFn('system/commoditdetails/updatebyid', data, function(jsonData) {
							console.log(jsonData)
							if(jsonData.htmlState.status == 200) {
								layer.msg("修改成功");
								layer.closeAll();
							}

						});

					}
				</script>
			</div>
			<!-- 概述 end-->
		</div>
	</body>

</html>